/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package fuzzyLogic;

import java.util.*;

/**
 *
 * @author CygiDawid
 */
public class LinguisticVariable {
    private final String _name;
    private final ArrayList<VariableSet> _sets;
    private double _from ;
    private double _to;
    private double _step;
    
    private int _valuesCount;
    private ArrayList<double[]> _sets2;
    
    
    public LinguisticVariable(String name, double from, double to, double step) {
        _sets = new  ArrayList();
        _name = name;
        _from = from;
        _to = to;
        _step = step;
        
        
        _valuesCount = (int)((_to - _from) / _step) + 1;
        _sets2 = new ArrayList();
    }
    
    
    public String getName() {
        return _name;
    }
    
    public void addSet(String name, double from, double mid, double to) {
        double[] result = new double[_valuesCount];
        for (int i = 0; i < _valuesCount; i++) {
            double value = _from + _step * i;
            result[i] = 0d;
        }
        
        _sets2.add(result);
        
        
        
        _sets.add(new VariableTriangle(name, from, mid, to, _step));
    }
    
    public void addSet(String name, double from, double mid1, double mid2, double to) {
        _sets.add(new VariableTrapezium(name, from, mid1, mid2, to, _step));
    }
    
    /**
     * @param value Wartość, której przynależność do termów ma zostać obliczona
     * @return Przynależność podanej wartości do poszczególnych termów (w kolejności dodawania termów)
    */
    public double[] getAffiliations(double value) {
        double[] result = new double[_sets.size()];
        
        for (int i = 0; i < _sets.size(); i++) {
            result[i] = _sets.get(i).getAffiliation(value);
        }
        
        return result;
    }
}
